import pandas as pd
from pyndamics3 import Simulation
from pyndamics3.fit import fit, Parameter
Populating the interactive namespace from numpy and matplotlib
pyndamics3  version  0.0.29
df = pd.read_excel('Mobile telephone service.xlsx')
x_data=df['Year']
y_data=df['Americans with Cellular Service (%)']
sim=Simulation()
sim.add("y'= a*y*(1-y/k)",12,plot=True)
sim.params(a=0.3,k=100)
sim.add_data(t=x_data,y=y_data,plot=True)
sim.run(1995,2012)

<Figure size 864x576 with 0 Axes>
results=fit(sim,
           Parameter("a",value=0.5,min=0),
           Parameter("k",value=100,min=0),
           )
sim.run(1995,2012)

<Figure size 864x576 with 0 Axes>
results

Fit Statistics

fitting method leastsq
# function evals 7
# data points 18
# variables 2
chi-square 14627.1940
reduced chi-square 914.199625
Akaike info crit. 124.604787
Bayesian info crit. 126.385530

Variables

name value initial value min max vary
a 0.50000000 0.5 0.00000000 inf True
k 58.0001111 100 0.00000000 inf True
x_data=x_data-min(x_data)
sim=Simulation()
sim.add("y'= a*y*(1-y/k)",12,plot=True)
sim.params(a=0.3,k=100)
sim.add_data(t=x_data,y=y_data,plot=True)
sim.run(20)

<Figure size 864x576 with 0 Axes>
results=fit(sim,
           Parameter("a",value=0.5,min=0),
           Parameter("k",value=100,min=0),
           )
sim.run(20)

<Figure size 864x576 with 0 Axes>
results

Fit Statistics

fitting method leastsq
# function evals 16
# data points 18
# variables 2
chi-square 30.6986915
reduced chi-square 1.91866822
Akaike info crit. 13.6092689
Bayesian info crit. 15.3900124

Variables

name value standard error relative error initial value min max vary
a 0.27934262 0.00382039 (1.37%) 0.5 0.00000000 inf True
k 103.234169 1.20806071 (1.17%) 100 0.00000000 inf True

Correlations (unreported correlations are < 0.100)

a k -0.8281
results=fit(sim,
           Parameter("a",value=1,min=0,max=20),
           Parameter("initial_y",value=1,min=0),
           Parameter("k",value=30,min=0),
           )
results

Fit Statistics

fitting method leastsq
# function evals 9
# data points 18
# variables 3
chi-square 14627.1940
reduced chi-square 975.146267
Akaike info crit. 126.604787
Bayesian info crit. 129.275902

Variables

name value initial value min max vary
a 1.00000000 1 0.00000000 20.0000000 True
initial_y 1.00000000 1 0.00000000 inf True
k 58.0001111 30 0.00000000 inf True
sim.run(1995,2012)

<Figure size 864x576 with 0 Axes>
fishery = pd.read_csv("FISH_LAND_08032022184748990.csv")
fishery=fishery[fishery['MEASURE']=='TON']
fishery=fishery[fishery['Species']=='TOTAL SPECIES']
fishery=fishery[fishery['LANDINGS']=='LAND_TOTAL']
t_fishery=fishery['Year']
y_fishery=fishery['Value']
r=0.13
a=5000
k=170000
h=0.1
sim=Simulation()
sim.add("n'=r*n*(1-(n/k))-h*(n/(a+n))",80000,plot=True)
sim.params(r=0.13,a=5000,k=170000,h=0.1)
sim.add_data(t=t_fishery,n=y_fishery,plot=True)
sim.run(2001,2018)
results=fit(sim,
           Parameter("r",value=1,min=0,max=10),
           Parameter("a",value=100,min=0),
           Parameter("k",value=100,min=0),
           Parameter("h",value=100,min=0),
        )
sim=Simulation()
sim.add("y' = a*y*(1-y/k)",1,plot=True)
sim.params(a=1,k=30)
sim.add_data(t=t_data,y=h_data,plot=True)
sim.run(80)